<script>
	import Vue from 'vue'
	import initApp from '@/common/appInit.js';
	import openApp from '@/common/openApp.js';
	import store from '@/store'
	import updateCustomBarInfo from './tuniao-ui/libs/function/updateCustomBarInfo.js'
	import checkIsAgree from '@/pages/uni-agree/utils/uni-agree.js';

	export default {
		globalData: {
			searchText: '',
			appVersion: {},
			config: {},
			$i18n: {},
			$t: {}
		},
		onLaunch: function() {
			console.log('App Launch')
			uni.hideTabBar({})
			this.globalData.$i18n = this.$i18n
			this.globalData.$t = str => this.$t(str)

			initApp();

			// #ifdef H5
			openApp() //创建在h5端全局悬浮引导用户下载app的功能
			// #endif
			// 获取设备的状态栏信息和自定义顶栏信息
			// store.dispatch('updateCustomBarInfo')
			updateCustomBarInfo().then((res) => {
				store.commit('$tStore', {
					name: 'vuex_status_bar_height',
					value: res.statusBarHeight
				})
				store.commit('$tStore', {
					name: 'vuex_custom_bar_height',
					value: res.customBarHeight
				})
			})

			// #ifdef APP-PLUS
			//checkIsAgree(); APP端暂时先用原生默认生成的。目前，自定义方式启动vue界面时，原生层已经请求了部分权限这并不符合国家的法规
			// 监听push推送通知
			plus.push.addEventListener('receive', ({
				type,
				title,
				content,
				payload
			}) => { //console.log(type,title,content,payload);
				console.log(type, 'type');
				if (type == 'receive' || uni.getSystemInfoSync().platform !=
					"ios") { //如果type!='receive'是自己本地插件的push消息栏，“拦截”避免死循环'，安卓系统没有这个问题
					if (typeof payload != 'object') {
						payload = JSON.parse(payload)
					} //判断是否为object，不是的话手动转一下。hbuilderx 3.0以上版本已经修复此问题可省略
					plus.push.createMessage(content, JSON.stringify(payload), {
						title: payload.title,
						subtitle: payload.content
					});
				}
			});
			//监听点击通知栏
			plus.push.addEventListener('click', function({
				payload
			}) {
				if (typeof payload != 'object') {
					payload = JSON.parse(payload)
				}
				console.log('用户点击了通知')
				// 清除角标
				plus.runtime.setBadgeNumber(0);
				let pages = getCurrentPages();
				let currentWebview = pages[pages.length - 1].route;
				if (currentWebview != 'pages/list/notice') {
					uni.navigateTo({
						url: '/pages/list/notice'
					})
				}
			});
			// #endif


			// #ifdef APP-PLUS
			//idfa有需要的用户在应用首次启动时自己获取存储到storage中
			//https://ask.dcloud.net.cn/article/36107
			/*if(~plus.storage.getItem('idfa')){
				plus.device.getInfo({//需要勾选IDFA
					success:function(e){  
						console.log('idfa =  '+JSON.stringify(e.idfa));  
					},
					fail:function(e){
						console.log('getDeviceInfo failed: '+JSON.stringify(e));  
					}  
				});
			}*/
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import './tuniao-ui/index.scss';
	@import './tuniao-ui/iconfont.css';
</style>
